import { BroadCastCall } from "../../broadCast/BroadCastCall";
import { MessageBlock } from "../../../../../Framework/MQ/MessageBlock";
import { SGroupInvite } from "../../../../../Message/Public/SGroupInvite";
import { SGroupInviteEx } from "../../../../../Message/Public/SGroupInviteEx";
import { NetDispatcher } from "../../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../../mvc/ServerCommand";
//class GroupInviteCommand
    
    export  class GroupInviteCommand extends BroadCastCall
    {
        constructor(arg1: Object)
        {
            super(arg1);
            return;
        }

        public /* override */ call(arg1: MessageBlock): void
        {
            var loc5=null;
            var loc6=null;
            super.call(arg1);
            var loc1=arg1.messageBase as SGroupInvite;
            var loc2=_cache.group.inviteList;
            var loc3=false;
            var loc4=0;
            while (loc4 < loc2.length) 
            {
                if (typeof loc2[loc4] === "sgroupinvite") 
                {
                    if ((loc5 = loc2[loc4] as SGroupInvite).player.entityId.id == loc1.player.entityId.id) 
                    {
                        loc3 = true;
                        break;
                    }
                }
                else if (typeof loc2[loc4] === "sgroupinviteex") 
                {
                    if ((loc6 = loc2[loc4] as SGroupInviteEx).groupInfo.captainId.id == loc1.player.entityId.id) 
                    {
                        loc3 = true;
                        break;
                    }
                }
                ++loc4;
            }
            if (!loc3) 
            {
                if (loc2.length < 5) 
                {
                    loc2.push(loc1);
                }
                else 
                {
                    loc2.splice(0, 1);
                    loc2.push(loc1);
                }
            }
            NetDispatcher.dispatchCmd(ServerCommand.Group_Invite, loc1);
            return;
        }
    }
